function Invoke-SQLScript {
    param (
        [Parameter(Mandatory=$true)][string]$ServerName,
        [Parameter(Mandatory=$true)][string]$DatabaseName,
        [Parameter(Mandatory=$true)][pscredential]$Credential,
        [Parameter(Mandatory=$true)][string]$File
    )

    $params = @{
        'ServerInstance' = $ServerName;
        'Database' = $DatabaseName;
        'Username' = $Credential.UserName;
        'Password' = ($Credential.Password | ConvertTo-LSPlainText);
        'InputFile' = $File
    }

    Invoke-Sqlcmd @params -ErrorAction Stop
}